package com.spring.validator_test;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.beans.PropertyEditorSupport;

@Component
public class EmployeeEditor extends PropertyEditorSupport {


	public void setAsText(String text) throws IllegalArgumentException {
		Employee convert = convert(text);
		setValue(convert);
//		super.setAsText(convert);
	}
	private Employee convert(String source) {
		if(source!= null){
			String[] val = source.split("-");
			if(val != null && val.length == 3){
				String name = val[0];
				Integer age = Integer.valueOf(val[1]);
				//时间
				Employee employee = new Employee(name,age,null,null);
				return employee;
			}
		}

		return null;
	}
}
